package parttern.absfactory;

public enum FactoryProducer {
    SHAPE(new ShapeFactory(), "SHAPE"), COLOR(new ColorFactory(), "COLOR");

    private AbsFactory factory;
    private String name;

    FactoryProducer(AbsFactory factory, String name) {
        this.factory = factory;
        this.name = name;
    }

    public static AbsFactory getFactory(String factoryName) {
        for (FactoryProducer producer : FactoryProducer.values()) {
            if (producer.name.equals(factoryName)) {
                return producer.factory;
            }
        }
        return null;
    }


    ///test
    public static void main(String[] args) {
        FactoryProducer.getFactory("SHAPE").getShape("CIRCLE").draw();
        FactoryProducer.getFactory("COLOR").getColor("RED").fill();

    }
}
